package io.wongd.lib_douyin.util

import android.content.Context
import android.content.Intent
import android.net.Uri
import android.os.Build
import io.wongxd.solution.util.FileUtilW
import java.io.File

object OpenVideo {

    fun open(context: Context, file: File?): Boolean {
        file ?: return false
        val intent = Intent(Intent.ACTION_VIEW)
        intent.putExtra("oneshot", 0)
        intent.putExtra("configchange", 0)
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            intent.flags = Intent.FLAG_GRANT_READ_URI_PERMISSION
            val contentUri = FileUtilW.getFileUri(context, file.absolutePath)
            intent.setDataAndType(contentUri, "video/*")
        } else {
            intent.setDataAndType(Uri.fromFile(file), "video/*")
            intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
        }
        context.startActivity(intent)
        return true
    }


}